package gold.digger;

import gold.utils.InputUtil;
import gold.vo.TreeNode;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC653 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public boolean findTarget(TreeNode root, int k) {
            return findRecur(root, k, new HashSet<>());
        }

        public boolean findRecur(TreeNode root, int k, Set<Integer> memo) {
            if (root == null) return false;
            if (memo.contains(k - root.val)) return true;
            memo.add(root.val);
            return findRecur(root.left, k, memo) || findRecur(root.right, k, memo);
        }
    }

    public void run() {
        System.out.println(new Solution().findTarget(TreeNode.createTree("[5,3,6,2,4,null,7]"), 9));
        System.out.println(new Solution().findTarget(TreeNode.createTree("[5,3,6,2,4,null,7]"), 28));
    }

    public static void main(String[] args) throws Exception {
        LC653 an = new LC653();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
